﻿using System;
using System.IO;
using System.Linq;
using Fluffy.Library.DocumentContainer;
using Fluffy.Library.FileSources;
using Fluffy.Library.Mvvm;

namespace Fluffy.Archive
{
	public class ArchiveDocument : IDocumentContainer
	{
		private readonly string[] _supportedExtensions =
		{
			".7z",
			".XZ",
			".BZIP2",
			".GZIP",
			".TAR",
			".ZIP",
			".WIM",
			".ARJ",
			".CAB",
			".CHM",
			".CPIO",
			".CramFS",
			".DEB",
			".DMG",
			".FAT",
			".HFS",
			".ISO",
			".LZH",
			".LZMA",
			".MBR",
			".MSI",
			".NSIS",
			".NTFS",
			".RAR",
			".RPM",
			".SquashFS",
			".UDF",
			".VHD",
			".WIM",
			".XAR",
			".Z"
		};

		public string Title
		{
			get { return "Archive"; }
		}

		public DocumentViewModelBase GenerateViewModel(IFile file)
		{
			ArchiveDocumentModel model = new ArchiveDocumentModel(file);
			return new ArchiveDocumentViewModel(model);
		}

		public bool IsFileExtensionSupported(IFile file)
		{
			string extension = Path.GetExtension(file.FileName);
			return _supportedExtensions.Any(x => x.Equals(extension, StringComparison.InvariantCultureIgnoreCase));
		}
	}
}
